using System;
using System.Linq;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.Configuration;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Helpers;

namespace ASPNETVN.PORTAL.Modules.MODULE
{
    public partial class ModuleType : PortalModuleControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.ModuleTitle.AddUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "AddEditModule", "");

                PortalConfiguration config = new PortalConfiguration();
                dlModuleDefinitions.DataSource = config.GetModuleDefinitions(this.Portal.ID);
                dlModuleDefinitions.DataBind();
            }
        }

        protected void dlModuleDefinitions_EditCommand(object source, DataListCommandEventArgs e)
        {
            Guid moduleDefinitionID = new Guid(dlModuleDefinitions.DataKeys[e.Item.ItemIndex].ToString());
            string url = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "AddEditModule", "mdid={0}", moduleDefinitionID);
            Response.Redirect(url);
        }
    }
}